package com.eshipenet.shipnet.edgechannelbuilder

import play.api.libs.json.{JsNull, JsObject, Json}

trait EdgeChannelAction {
  def toJson: JsObject
}
case class EdgeChannelInsert(after: EdgeChannel) extends EdgeChannelAction {
  override def toJson: JsObject = Json.obj(
    "payload" -> Json.obj(
      "op" -> "c",
      "ts_ms" -> 0,
      "before" -> JsNull,
      "after" -> Json.toJson(after),
      "source" -> Json.obj()
    )
  )
}
case class EdgeChannelUpdate(before: EdgeChannel, after: EdgeChannel)
    extends EdgeChannelAction {
  override def toJson: JsObject = Json.obj(
    "payload" -> Json.obj(
      "op" -> "u",
      "ts_ms" -> 0,
      "before" -> Json.toJson(before),
      "after" -> Json.toJson(after),
      "source" -> Json.obj()
    )
  )
}
case class EdgeChannelDelete(before: EdgeChannel) extends EdgeChannelAction {
  override def toJson: JsObject = Json.obj(
    "payload" -> Json.obj(
      "op" -> "c",
      "ts_ms" -> 0,
      "before" -> Json.toJson(before),
      "after" -> JsNull,
      "source" -> Json.obj()
    )
  )
}
